home *** CD-ROM | disk | FTP | other *** search
- Path: news.sni.de!news
- From: Josef Moellers <mollers.pad@sni.de>
- Newsgroups: comp.lang.c
- Subject: Re: Help on Dynamically Allocating an Array?
- Date: 11 Jan 1996 08:06:08 GMT
- Organization: Siemens Nixdorf Informationssysteme AG, Paderborn, Germany
- Message-ID: <4d2gdg$t3m@nervous.pdb.sni.de>
- References: <4cq273$aeq@mercury.IntNet.net>
- NNTP-Posting-Host: uranium.pdb.sni.de
- X-Newsreader: NN version 6.5.0 #2
-
- In <4cq273$aeq@mercury.IntNet.net> jtomich@IntNet.net (Jeff Tomich) writes:
-
- >I'm confused on who to dynamically allocate an array of any type. Any
- >help would be much appreciated.
-
- Either
-
- type *pointer;
- ...
- pointer = (type *) malloc(nitems * sizeof(type));
-
- or
-
- ...
- pointer = (type *) calloc(nitems, sizeof(type));
-
-
- The latter explicitly initializes the array to all zeroes, while the
- former only does this (implicitly) if the memory for the array will have
- to be obtained by asking the OS for it. In that case, the OS will
- usually clear whatever memory it gives your process to avoid security
- problems.
-
- Access in both cases is
-
- pointer[index]
-
- Hope this helps,
-
- Josef
- --
- Josef Moellers mollers.pad@sni.de
-